package com.tvunetworks.center.user.mapper;


import com.tvunetworks.center.common.model.param.ListUserPeerIdsParam;
import com.tvunetworks.center.common.model.vo.PeerIdWithName;
import com.tvunetworks.center.gs.model.Device;
import com.tvunetworks.center.user.model.PageInfoBookMarkParam;
import com.tvunetworks.center.user.model.TokenDevice;
import com.tvunetworks.center.user.model.UserDevice;
import com.tvunetworks.center.user.model.json.RExtRelation;
import com.tvunetworks.center.user.model.param.SearchUserDeviceParam;
import com.tvunetworks.center.user.model.param.api.GetUserReceiverParam;
import com.tvunetworks.center.user.model.vo.*;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.additional.idlist.DeleteByIdListMapper;
import tk.mybatis.mapper.additional.insert.InsertListMapper;
import tk.mybatis.mapper.common.Mapper;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author HenryChen
 * @program:
 * @description:
 * @create: 5/29/2019 12:17 PM
 **/
public interface UserDeviceMapper extends Mapper<UserDevice>, InsertListMapper<UserDevice>, DeleteByIdListMapper<UserDevice, String> {
    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserRIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserTIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserPackIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserAnywhereIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserXIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserGridPackIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserGridSdiIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId    userId
     * @param condition condition
     * @param types     types
     * @return List
     */
    List<String> listUserDevice(@Param("userId") String userId, @Param("condition") String condition, @Param("types") String types);

    /**
     * @param peerIds   peerIds
     * @param condition condition
     * @return List
     */
    List<Device> listDevice(@Param("peerIds") Collection<String> peerIds, @Param("condition") String condition);

    /**
     * @param peerIds peerIds
     * @return List
     */
    List<RCListRVo> listRCListRVo(@Param("peerIds") List<String> peerIds);

    /**
     * @param userId    userId
     * @param condition condition
     * @param types     types
     * @return List
     */
    List<String> listUserExt(@Param("userId") String userId, @Param("condition") String condition, @Param("types") String types);

    /**
     * @param filterTypePeerIds filterTypePeerIds
     * @return List
     */
    List<RCListSourceVo> listRCSourceVo(@Param("filterTypePeerIds") List<String> filterTypePeerIds);

    /**
     * @param userId        userId
     * @param condition     condition
     * @param typeCondition typeCondition
     * @return List
     */
    List<String> listUserPeerIdFilterByTypeAndCondition(@Param("userId") String userId, @Param("condition") String condition, @Param("typeCondition") String typeCondition);


    /**
     * 通过用户查source
     *
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserTokenTids(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * @param userId userId
     * @param rid    rid
     * @return List
     */
    List<String> listUserTokenTidsRegardlessOfUser(@Param("userId") String userId, @Param("rid") String rid);

    /**
     * @param userId userId
     * @param name   name
     * @param types  types
     * @return List
     */
    List<String> listUserExistExt(@Param("userId") String userId, @Param("name") String name, @Param("types") String types);

    /**
     * @param userId userId
     * @param type   type
     * @return List
     */
    List<String> listUserDeviceIds(@Param("userId") String userId, @Param("type") String type);

    /**
     * @param userId userId
     * @return List
     */
    List<String> listUserAllDeviceIds(@Param("userId") String userId);

    /**
     * @param userId userId
     * @return List
     */
    List<String> listUserRTXIds(@Param("userId") String userId);

    /**
     * 根据用户查询 token 配对的 grid id
     *
     * @param userId    userId
     * @param condition condition
     * @return List
     */
    List<String> listUserTokenGridIds(@Param("userId") String userId, @Param("condition") String condition);


    /**
     * 只查询设备的id和name
     *
     * @param userId    userId
     * @param condition condition
     * @param types     types
     * @return List
     */
    List<SimpleDeviceVo> listUserSimpleDevice(@Param("userId") String userId, @Param("condition") String condition, @Param("types") String types);

    /**
     * @param userId userId
     * @return int
     */
    int countReceiver(String userId);

    /**
     * @param userId userId
     * @return int
     */
    int countSource(String userId);

    /**
     * @param userIds userIds
     */
    void removeUserDevice(@Param("userIds") List<String> userIds);

    /**
     * 查询用户绑定的设备
     *
     * @param param param
     * @return List
     */
    List<SearchUserDeviceVo> listSettingPageUserBindDevice(SearchUserDeviceParam param);

    /**
     * setting页面绑定设备时，根据条件查询所有设备
     *
     * @param param param
     * @return List
     */
    List<SearchUserDeviceVo> listSettingPageSupportDevice(SearchUserDeviceParam param);


    /**
     * 根据Pids查询SearchUserDeviceVo
     *
     * @param allPids allPids
     * @return List
     */
    List<SearchUserDeviceVo> listSearchUserDeviceVoByPids(@Param("allPids") List<String> allPids);

    /**
     * Support 列出和设备有绑定关系的用户
     *
     * @param peerId peerId
     * @return List
     */
    List<BindDeviceUserVo> listDeviceBindUser(@Param("peerId") String peerId);

    /**
     * @param userId    userId
     * @param condition condition
     * @param ext       ext
     * @param youtube   youtube
     * @param smpte2022 smpte2022
     * @return List
     */
    List<String> listUserExtIds(@Param("userId") String userId, @Param("condition") String condition, @Param("ext") boolean ext, @Param("youtube") boolean youtube, @Param("smpte2022") boolean smpte2022);

    /**
     * @param peerIds peerIds
     * @return List
     */
    List<ExtVo> listExtVo(@Param("peerIds") List<String> peerIds);

    /**
     * @param peerIds peerIds
     * @return List
     */
    List<ExtBindReceiverVo> listExtBindReceiverVo(@Param("peerIds") List<String> peerIds);

    /**
     * @param userIdList userIdList
     * @param peerId     peerId
     */
    void removeDevivecBindUser(@Param("userIdList") List<String> userIdList, @Param("peerId") String peerId);


    /**
     * //跟据设备id和当前登录用户id(或者待分享的userid)获取token device设备列表
     *
     * @param peerOrName peerOrName
     * @param userId     userId
     * @return List
     * @throws Exception 编译
     */
    List<SearchUserDeviceVo> queryTokenDeviceList(@Param("peerIdOrName") String peerOrName, @Param("userId") String userId) throws Exception;


    /**
     * //保存token device的数据
     *
     * @param tokenDeviceParam tokenDeviceParam
     * @throws Exception 编译异常
     */
    void saveTokenDevice(TokenDevice tokenDeviceParam) throws Exception;


    /**
     * //移除token device的数据
     *
     * @param peerId peerId
     * @param userId userId
     * @throws Exception 编译
     */
    void removeTokenDevice(@Param("peerId") String peerId, @Param("userId") String userId) throws Exception;


    /**
     * //根据用户id和设备id查询出最大过期时间的code
     *
     * @param peerId peerId
     * @param userId userId
     * @return String
     * @throws Exception 编译异常
     */
    String getMaxExipreCode(@Param("peerId") String peerId, @Param("userId") String userId) throws Exception;

    /**
     * @param peerId1 peerId1
     * @param peerId2 peerId2
     * @return List
     */
    List<String> containBothDeviceUser(@Param("peerId1") String peerId1, @Param("peerId2") String peerId2);

    /**
     * @param userId userId
     * @return List
     */
    List<String> getBindTRPeerIdList(String userId);

    /**
     * @param userId userId
     * @return List
     */
    List<Device> getUnBindReceiverList(String userId);

    /**
     * @param userId userId
     * @return List
     */
    List<String> getTListByUser(String userId);

    /**
     * @param param param
     * @return List
     */
    List<PeerIdWithName> listUserReceiver(GetUserReceiverParam param);

    /**
     * @param oldPeerId oldPeerId
     * @param newPeerId newPeerId
     * @return List
     */
    List<String> listUserIdsInPeerId1NotInPeerId2(@Param("oldPeerId") String oldPeerId, @Param("newPeerId") String newPeerId);

    /**
     * @param userIds userIds
     * @param peerIds peerIds
     * @return List
     */
    List<String> listIdInUsersAndPeerIds(@Param("userIds") List<String> userIds, @Param("peerIds") List<String> peerIds);

    /**
     * @param userId userId
     * @return List
     */
    List<String> listOwnerPeerIds(@Param("userId") String userId);

    /**
     * @param peerId peerId
     * @return Device
     */
    Device getDevice(@Param("peerId") String peerId);

    /**
     * 定制化CC 查询 Channel，为了做分页，只查询 peerId，其余字段从缓存中取
     *
     * @param peerIds peerIds
     * @return List
     */
    List<CustomizedChannelVo> listCustomizedChannelVo(@Param("peerIds") List<String> peerIds);

    /**
     * @param peerId peerId
     * @return List
     */
    List<String> listDeviceBelongUser(@Param("peerId") String peerId);

    /**
     * @param peerIds   peerIds
     * @param condition condition
     * @return Set
     */
    Set<String> filterCondition(@Param("peerIds") Set<String> peerIds, @Param("condition") String condition);

    /**
     * @param param param
     * @return List
     */
    List<String> listUserPeerIds(ListUserPeerIdsParam param);

    /**
     * @param peerId peerId
     * @return List
     */
    List<String> listExistDeviceUser(@Param("peerId") String peerId);

    /**
     * @return List
     */
    List<Map<String, String>> listOwner();

    /**
     * @param userId userId
     * @param rids   rids
     * @return List
     */
    List<RExtRelation> listNeedRemoveRelation(@Param("userId") String userId, @Param("rids") Collection<String> rids);

    /**
     * @param ids ids
     */
    void deleteRExtRelation(@Param("ids") List<String> ids);

    /**
     * @param rid rid
     * @return List
     */
    List<String> listGridPeerIds(String rid);

    /**
     * @param peerIds peerIds
     * @return List
     */
    List<String> filterReceiver(@Param("peerIds") Collection<String> peerIds);

    /**
     * @return List
     */
    List<String> listExternalRRelationR();

    /**
     * @param rid rid
     * @return List
     */
    List<RExtRelation> listRNeedRemoveRelation(@Param("rid") String rid);

    /**
     * @param rid rid
     * @return List
     */
    List<RExtRelation> listRExtRelationByRid(@Param("rid") String rid);

    /**
     * 根据peerId查找device的信息
     *
     * @param peerIds   peerIds
     * @param condition condition
     * @return List
     */
    List<SearchUserDeviceVo> getDeviceByPeerIds(@Param("peerIds") Set<String> peerIds, @Param("condition") String condition);


    /**
     * //分页查询bookmark信息
     *
     * @param userId   userId
     * @param parentId parentId
     * @param search   search
     * @return List
     */
    List<PageInfoBookMarkParam> pageInfoBookMark(@Param("userId") String userId, @Param("parentId") String parentId, @Param("search") String search);


    /**
     * //查询bookmark下的R
     *
     * @param bookmarkId bookmarkId
     * @return List
     */
    List<String> selectRByBookmarkId(@Param("bookmarkId") String bookmarkId);


    /**
     * //分页查询bookmark下的R
     *
     * @param bookmarkId bookmarkId
     * @param search     search
     * @return List
     */
    List<Device> pageInfoRByBookMark(@Param("bookmarkId") String bookmarkId, @Param("search") String search);


    /**
     * //分页查询没有文件夹分类的R
     *
     * @param userId userId
     * @param search search
     * @return List
     */
    List<Device> pageInfoRNoBookMark(@Param("userId") String userId, @Param("search") String search);


    /**
     * 查询用户下owner的grid
     *
     * @param userId    userId
     * @param condition condition
     * @return java.util.List<java.lang.String>
     * @throws Exception if has error
     * @author KevinLi
     * @date 12/6/2021
     */
    List<String> listOwnerXIds(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * 通过用户Id,移除所有token配对的设备
     * @param ids    ids
     */
    void removeTokenDeviceByUserId(@Param("ids") List<String> ids);

    /**
     * 通过userId,通过token扫码,获取用户下已经配对的anywhere
     * @param userId    userId
     * @return String
     */
    List<String>  getAnyWhereByUserId(@Param("userId") String userId);

    /**
     * 通过userid  获取device 的peerid
     * @param userId userId
     * @return peerid集合
     */
    List<String> getDeviceByUserId(@Param("userId") String userId);

    /**
     * 根据userId和peerIds集合获取userDevice的集合
     * @param userId 用户id
     * @param peerIds peerId集合
     * @return 返回根据userId和peerIds集合获取userDevice的集合
     */
    List<UserDevice> listByUserIdAndPeerIds(@Param("userId") String userId, @Param("peerIds") List<String> peerIds);

    /**
     * 根据peerid和userId删除用户设备
     * @param peerId peerId
     * @param userId userId
     */
    void deleteDeviceByPeerId(@Param("peerId") String peerId ,  @Param("userId") String userId);

    /**
     *  根据url和用户id,查询该用户下的device
     * @param url  url
     * @param userId userId
     * @return Device
     */
    List<Device> getExtByUrlAndUserId(@Param("url")  String url, @Param("userId")String userId);

    /**
     * 查询用户下授权owner的Pack和X
     * @param userId userId
     * @param condition condition
     * @return List
     */
    List<String> listOwnerXAndPackId(@Param("userId") String userId, @Param("condition") String condition);
    /**
     * 查询用户下授权owner的Pack
     * @param userId userId
     * @param condition condition
     * @return List
     */
    List<String> listOwnerPackId(@Param("userId") String userId, @Param("condition") String condition);

    /**
     * 查询该用户下这个peerId是否是owner权限
     * @param userId userId
     * @param peerId peerId
     * @return 数量
     */
    Integer getOwnerByUserIdAndPeerId(@Param("userId") String userId,@Param("peerId")  String peerId);

}
